package com.example.muasic.provider;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.example.muasic.info.Info;
import com.example.muasic.permissions.PermissionHelper;

import java.util.ArrayList;
import java.util.List;

public class MusicSqLiteHelper extends SQLiteOpenHelper {
    private PermissionHelper permissionHelper;
    private String TAG = "PlayMusicActivity";
    String create_TABLE_Music="create table music(songId int,albumId int," +
            "albumName varchar(50),albumData varchar(50),duration int, musicName varchar(50),artist varchar(50),artistId int,data varchar(60)," +
            "folder varchar(50),lrc varchar(50),islocal int,sort varchar(50),favorite int)";

    String create_TABLE_FavMusic="create table favmusic(songId int,albumId int," +
            "albumName varchar(50),albumData varchar(50),duration int, musicName varchar(50),artist varchar(50),artistId int,data varchar(60)," +
            "folder varchar(50),lrc varchar(50),islocal int,sort varchar(50),favorite int)";

    String create_TABLE_Remusic="create table remusic(songId int,albumId int," +
            "albumName varchar(50),albumData varchar(50),duration int, musicName varchar(50),artist varchar(50),artistId int,data varchar(60)," +
            "folder varchar(50),lrc varchar(50),islocal int,sort varchar(50),favorite int)";

    public MusicSqLiteHelper(Context context, String databaseName, int version){
        super(context,databaseName,null,version);
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL(create_TABLE_Music);
        sqLiteDatabase.execSQL(create_TABLE_FavMusic);
        sqLiteDatabase.execSQL(create_TABLE_Remusic);
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {

    }

    public void addMusic(Info music){
        SQLiteDatabase sqLiteDatabase = getWritableDatabase();
        String sql = "insert into music(songid,albumId,albumName,albumData,duration,musicName,artist,artistId,data,folder,lrc,islocal,sort,favorite) values(?,?,?" +
                ",?,?,?,?,?,?,?,?,?,?,?)";
        sqLiteDatabase.execSQL(sql,new Object[]{music.getSongId(),music.getAlbumId(),music.getAlbumName(),
                music.getAlbumData(),music.getDuration(), music.getMusicName(),music.getArtist(),
                music.getArtistId(),music.getData(),music.getFolder(),music.getLrc(),music.getIslocal(),music.getSort(),music.getFavorite()});
        sqLiteDatabase.close();
    }

    public void addFavMusic(Info music){
        SQLiteDatabase sqLiteDatabase = getWritableDatabase();
        String sql = "insert into favmusic(songid,albumId,albumName,albumData,duration,musicName,artist,artistId,data,folder,lrc,islocal,sort,favorite) values(?,?,?" +
                ",?,?,?,?,?,?,?,?,?,?,?)";
        sqLiteDatabase.execSQL(sql,new Object[]{music.getSongId(),music.getAlbumId(),music.getAlbumName(),
                music.getAlbumData(),music.getDuration(), music.getMusicName(),music.getArtist(),
                music.getArtistId(),music.getData(),music.getFolder(),music.getLrc(),music.getIslocal(),music.getSort(),music.getFavorite()});
        sqLiteDatabase.close();
    }

    public void addRecMusic(Info music){
        SQLiteDatabase sqLiteDatabase = getWritableDatabase();
        String sql = "insert into remusic(songid,albumId,albumName,albumData,duration,musicName,artist,artistId,data,folder,lrc,islocal,sort,favorite) values(?,?,?" +
                ",?,?,?,?,?,?,?,?,?,?,?)";
        sqLiteDatabase.execSQL(sql,new Object[]{music.getSongId(),music.getAlbumId(),music.getAlbumName(),
                music.getAlbumData(),music.getDuration(), music.getMusicName(),music.getArtist(),
                music.getArtistId(),music.getData(),music.getFolder(),music.getLrc(),music.getIslocal(),music.getSort(),music.getFavorite()});
        sqLiteDatabase.close();
    }


    public void deleteFavMusic(long c){
        SQLiteDatabase sqLiteDatabase = getWritableDatabase();
        String sql = "delete from favmusic where songId = ? ";
        sqLiteDatabase.execSQL(sql,new Object[]{c});
        sqLiteDatabase.close();
    }

    public void deleteRecMusic(long c){
        SQLiteDatabase sqLiteDatabase = getWritableDatabase();
        String sql = "delete from remusic where songId = ? ";
        sqLiteDatabase.execSQL(sql,new Object[]{c});
        sqLiteDatabase.close();
    }

    public void delete(){
        SQLiteDatabase sqLiteDatabase = getWritableDatabase();
        String sql = "delete from music";
        sqLiteDatabase.execSQL(sql);
        sqLiteDatabase.close();
    }
    //判断最近
    public int searchRecMusic(long c){
        SQLiteDatabase sqLiteDatabase = getWritableDatabase();
        String sql = "select * from remusic where songId = ? ";
        Cursor cursor = sqLiteDatabase.rawQuery(sql, new String[]{""+c});
        if(cursor.moveToFirst()){
            cursor.close();
            sqLiteDatabase.close();
            return 1;
        }else {
            cursor.close();
            sqLiteDatabase.close();
            return 0;
        }
    }

    //判断爱心
    public int searchFavMusic(long c){
        SQLiteDatabase sqLiteDatabase = getWritableDatabase();
        String sql = "select * from favmusic where songId = ? ";
        Cursor cursor = sqLiteDatabase.rawQuery(sql, new String[]{""+c});
        if(cursor.moveToFirst()){
            cursor.close();
            sqLiteDatabase.close();
            return 1;
        }else {
            cursor.close();
            sqLiteDatabase.close();
            return 0;
        }
    }


    //返回本地搜索歌曲名字Se
    public List<String> SearchLocalmusicName(MusicSqLiteHelper musicSqLiteHelper,String SearchName){
        List<String> SemusicName = new ArrayList<>();
        SQLiteDatabase sqLiteDatabase = musicSqLiteHelper.getReadableDatabase();
        String sql = "select * from music where musicName like ?";
        Cursor cursor = sqLiteDatabase.rawQuery(sql,new String[]{SearchName+"%"});
        if(cursor.moveToFirst()) {
            cursor.moveToLast();
            do {

                String musicName = cursor.getString(cursor.getColumnIndex("musicName"));
                SemusicName.add(musicName);

            } while (cursor.moveToPrevious());
            cursor.close();
            sqLiteDatabase.close();
            return SemusicName;
        }else {
            cursor.close();
            sqLiteDatabase.close();
            return SemusicName;
        }
    }


    //返回本地搜索歌曲列表e
    public List<Info> SearchLocalmusic(MusicSqLiteHelper musicSqLiteHelper,String SearchName){
        List<Info> SemusicName = new ArrayList<>();
        SQLiteDatabase sqLiteDatabase = musicSqLiteHelper.getReadableDatabase();
        String sql = "select * from music where musicName like ?";
        Cursor cursor = sqLiteDatabase.rawQuery(sql,new String[]{SearchName+"%"});
        if(cursor.moveToFirst()){
            cursor.moveToLast();
            do{

                long songId = cursor.getInt(cursor.getColumnIndex("songId"));
                long albumId = cursor.getInt(cursor.getColumnIndex("albumId"));
                int duration = cursor.getInt(cursor.getColumnIndex("duration"));
                String albumName = cursor.getString(cursor.getColumnIndex("albumName"));
                String albumData = cursor.getString(cursor.getColumnIndex("albumData"));
                String musicName = cursor.getString(cursor.getColumnIndex("musicName"));
                String artist = cursor.getString(cursor.getColumnIndex("artist"));
                long artistId = cursor.getInt(cursor.getColumnIndex("artistId"));
                String data = cursor.getString(cursor.getColumnIndex("data"));
                String folder = cursor.getString(cursor.getColumnIndex("folder"));
                String lrc = cursor.getString(cursor.getColumnIndex("lrc"));
                String sort = cursor.getString(cursor.getColumnIndex("sort"));
                int islocal = cursor.getInt(cursor.getColumnIndex("islocal"));
                int favorite = cursor.getInt(cursor.getColumnIndex("favorite"));
                Info music1= new Info();
                music1.setSongId(songId);
                music1.setAlbumId(albumId);
                music1.setDuration(duration);
                music1.setAlbumName(albumName);
                music1.setAlbumData(albumData);
                music1.setMusicName(musicName);
                music1.setArtist(artist);
                music1.setArtistId(artistId);
                music1.setData(data);
                music1.setFolder(folder);
                music1.setLrc(lrc);
                music1.setSort(sort);
                music1.setIslocal(islocal);
                music1.setFavorite(favorite);
                SemusicName.add(music1);

            }while(cursor.moveToPrevious());
            cursor.close();
            sqLiteDatabase.close();
            return SemusicName;
        }else{
            cursor.close();
            sqLiteDatabase.close();
            return SemusicName;
        }

    }

    //返回local歌曲
    public List<Info>localmusic(MusicSqLiteHelper musicSqLiteHelper){
        List<Info> favmusicList=new ArrayList<>();
        SQLiteDatabase sqLiteDatabase = musicSqLiteHelper.getReadableDatabase();
        String sql = "select * from music";
        Cursor cursor = sqLiteDatabase.rawQuery(sql,null);
        cursor.moveToLast();
        do{
            long songId = cursor.getInt(cursor.getColumnIndex("songId"));
            long albumId = cursor.getInt(cursor.getColumnIndex("albumId"));
            int duration = cursor.getInt(cursor.getColumnIndex("duration"));
            String albumName = cursor.getString(cursor.getColumnIndex("albumName"));
            String albumData = cursor.getString(cursor.getColumnIndex("albumData"));
            String musicName = cursor.getString(cursor.getColumnIndex("musicName"));
            String artist = cursor.getString(cursor.getColumnIndex("artist"));
            long artistId = cursor.getInt(cursor.getColumnIndex("artistId"));
            String data = cursor.getString(cursor.getColumnIndex("data"));
            String folder = cursor.getString(cursor.getColumnIndex("folder"));
            String lrc = cursor.getString(cursor.getColumnIndex("lrc"));
            String sort = cursor.getString(cursor.getColumnIndex("sort"));
            int islocal = cursor.getInt(cursor.getColumnIndex("islocal"));
            int favorite = cursor.getInt(cursor.getColumnIndex("favorite"));
            Info music1= new Info();
            music1.setSongId(songId);
            music1.setAlbumId(albumId);
            music1.setDuration(duration);
            music1.setAlbumName(albumName);
            music1.setAlbumData(albumData);
            music1.setMusicName(musicName);
            music1.setArtist(artist);
            music1.setArtistId(artistId);
            music1.setData(data);
            music1.setFolder(folder);
            music1.setLrc(lrc);
            music1.setSort(sort);
            music1.setIslocal(islocal);
            music1.setFavorite(favorite);
            favmusicList.add(music1);

        }while(cursor.moveToPrevious());
        cursor.close();
        sqLiteDatabase.close();
        return favmusicList;
    }


    //返回收藏歌曲
    public List<Info> Favoritemusic(MusicSqLiteHelper musicSqLiteHelper){
        List<Info> favmusicList=new ArrayList<>();
        SQLiteDatabase sqLiteDatabase = musicSqLiteHelper.getReadableDatabase();
        String sql = "select * from favmusic";
        Cursor cursor = sqLiteDatabase.rawQuery(sql,null);
        cursor.moveToLast();
        do{
            long songId = cursor.getInt(cursor.getColumnIndex("songId"));
            long albumId = cursor.getInt(cursor.getColumnIndex("albumId"));
            int duration = cursor.getInt(cursor.getColumnIndex("duration"));
            String albumName = cursor.getString(cursor.getColumnIndex("albumName"));
            String albumData = cursor.getString(cursor.getColumnIndex("albumData"));
            String musicName = cursor.getString(cursor.getColumnIndex("musicName"));
            String artist = cursor.getString(cursor.getColumnIndex("artist"));
            long artistId = cursor.getInt(cursor.getColumnIndex("artistId"));
            String data = cursor.getString(cursor.getColumnIndex("data"));
            String folder = cursor.getString(cursor.getColumnIndex("folder"));
            String lrc = cursor.getString(cursor.getColumnIndex("lrc"));
            String sort = cursor.getString(cursor.getColumnIndex("sort"));
            int islocal = cursor.getInt(cursor.getColumnIndex("islocal"));
            int favorite = cursor.getInt(cursor.getColumnIndex("favorite"));
            Info music1= new Info();
            music1.setSongId(songId);
            music1.setAlbumId(albumId);
            music1.setDuration(duration);
            music1.setAlbumName(albumName);
            music1.setAlbumData(albumData);
            music1.setMusicName(musicName);
            music1.setArtist(artist);
            music1.setArtistId(artistId);
            music1.setData(data);
            music1.setFolder(folder);
            music1.setLrc(lrc);
            music1.setSort(sort);
            music1.setIslocal(islocal);
            music1.setFavorite(favorite);
            favmusicList.add(music1);

        }while(cursor.moveToPrevious());
        cursor.close();
        sqLiteDatabase.close();
        return favmusicList;
    }
    //返回喜爱歌曲名字
    public List<String> FavoritemusicName(MusicSqLiteHelper musicSqLiteHelper){
        List<String> FavoritemusicName = new ArrayList<>();
        SQLiteDatabase sqLiteDatabase = musicSqLiteHelper.getReadableDatabase();
        String sql = "select * from favmusic";
        Cursor cursor = sqLiteDatabase.rawQuery(sql,null);
        cursor.moveToLast();
        do{

            String musicName = cursor.getString(cursor.getColumnIndex("musicName"));
            FavoritemusicName.add(musicName);

        }while(cursor.moveToPrevious());
        cursor.close();
        sqLiteDatabase.close();
        return FavoritemusicName;
    }



    //返回最近歌曲
    public List<Info> RecmusicList(MusicSqLiteHelper musicSqLiteHelper){
        List<Info> remusicList=new ArrayList<>();
        SQLiteDatabase sqLiteDatabase = musicSqLiteHelper.getReadableDatabase();
        String sql = "select * from remusic";
        Cursor cursor = sqLiteDatabase.rawQuery(sql,null);
        cursor.moveToLast();
        do{
            long songId = cursor.getInt(cursor.getColumnIndex("songId"));
            long albumId = cursor.getInt(cursor.getColumnIndex("albumId"));
            int duration = cursor.getInt(cursor.getColumnIndex("duration"));
            String albumName = cursor.getString(cursor.getColumnIndex("albumName"));
            String albumData = cursor.getString(cursor.getColumnIndex("albumData"));
            String musicName = cursor.getString(cursor.getColumnIndex("musicName"));
            String artist = cursor.getString(cursor.getColumnIndex("artist"));
            long artistId = cursor.getInt(cursor.getColumnIndex("artistId"));
            String data = cursor.getString(cursor.getColumnIndex("data"));
            String folder = cursor.getString(cursor.getColumnIndex("folder"));
            String lrc = cursor.getString(cursor.getColumnIndex("lrc"));
            String sort = cursor.getString(cursor.getColumnIndex("sort"));
            int islocal = cursor.getInt(cursor.getColumnIndex("islocal"));
            int favorite = cursor.getInt(cursor.getColumnIndex("favorite"));
            Info music1= new Info();
            music1.setSongId(songId);
            music1.setAlbumId(albumId);
            music1.setDuration(duration);
            music1.setAlbumName(albumName);
            music1.setAlbumData(albumData);
            music1.setMusicName(musicName);
            music1.setArtist(artist);
            music1.setArtistId(artistId);
            music1.setData(data);
            music1.setFolder(folder);
            music1.setLrc(lrc);
            music1.setSort(sort);
            music1.setIslocal(islocal);
            music1.setFavorite(favorite);
            remusicList.add(music1);

        }while(cursor.moveToPrevious());
        cursor.close();
        sqLiteDatabase.close();
        return remusicList;
    }

    //返回最近歌曲名字
    public List<String> RecmusicName(MusicSqLiteHelper musicSqLiteHelper){
        List<String> remusicName = new ArrayList<>();
        SQLiteDatabase sqLiteDatabase = musicSqLiteHelper.getReadableDatabase();
        String sql = "select * from remusic";
        Cursor cursor = sqLiteDatabase.rawQuery(sql,null);
        cursor.moveToLast();
        do{

            String musicName = cursor.getString(cursor.getColumnIndex("musicName"));
            remusicName.add(musicName);

        }while(cursor.moveToPrevious());
        cursor.close();
        sqLiteDatabase.close();
        return remusicName;
    }


    //返回搜索收藏歌曲名字
    public List<String> SearchFavmusicName(MusicSqLiteHelper musicSqLiteHelper,String SearchName){
        List<String> SemusicName = new ArrayList<>();
        SQLiteDatabase sqLiteDatabase = musicSqLiteHelper.getReadableDatabase();
        String sql = "select * from favmusic where musicName like ?";
        Cursor cursor = sqLiteDatabase.rawQuery(sql,new String[]{SearchName+"%"});
        cursor.moveToLast();
        do{

            String musicName = cursor.getString(cursor.getColumnIndex("musicName"));
            SemusicName.add(musicName);

        }while(cursor.moveToPrevious());
        cursor.close();
        sqLiteDatabase.close();
        return SemusicName;
    }
    //返回收藏搜索歌曲列表
    public List<Info> SearchFavmusic(MusicSqLiteHelper musicSqLiteHelper,String SearchName){
        List<Info> SemusicName = new ArrayList<>();
        SQLiteDatabase sqLiteDatabase = musicSqLiteHelper.getReadableDatabase();
        String sql = "select * from favmusic where musicName like ?";
        Cursor cursor = sqLiteDatabase.rawQuery(sql,new String[]{SearchName+"%"});
        cursor.moveToLast();
        do{

            long songId = cursor.getInt(cursor.getColumnIndex("songId"));
            long albumId = cursor.getInt(cursor.getColumnIndex("albumId"));
            int duration = cursor.getInt(cursor.getColumnIndex("duration"));
            String albumName = cursor.getString(cursor.getColumnIndex("albumName"));
            String albumData = cursor.getString(cursor.getColumnIndex("albumData"));
            String musicName = cursor.getString(cursor.getColumnIndex("musicName"));
            String artist = cursor.getString(cursor.getColumnIndex("artist"));
            long artistId = cursor.getInt(cursor.getColumnIndex("artistId"));
            String data = cursor.getString(cursor.getColumnIndex("data"));
            String folder = cursor.getString(cursor.getColumnIndex("folder"));
            String lrc = cursor.getString(cursor.getColumnIndex("lrc"));
            String sort = cursor.getString(cursor.getColumnIndex("sort"));
            int islocal = cursor.getInt(cursor.getColumnIndex("islocal"));
            int favorite = cursor.getInt(cursor.getColumnIndex("favorite"));
            Info music1= new Info();
            music1.setSongId(songId);
            music1.setAlbumId(albumId);
            music1.setDuration(duration);
            music1.setAlbumName(albumName);
            music1.setAlbumData(albumData);
            music1.setMusicName(musicName);
            music1.setArtist(artist);
            music1.setArtistId(artistId);
            music1.setData(data);
            music1.setFolder(folder);
            music1.setLrc(lrc);
            music1.setSort(sort);
            music1.setIslocal(islocal);
            music1.setFavorite(favorite);
            SemusicName.add(music1);

        }while(cursor.moveToPrevious());
        cursor.close();
        sqLiteDatabase.close();
        return SemusicName;
    }

    //字母顺序排序
    public List<Info> Alphabetmusic(MusicSqLiteHelper musicSqLiteHelper){
        List<Info> musicList = new ArrayList<>();
        SQLiteDatabase sqLiteDatabase = musicSqLiteHelper.getReadableDatabase();
        String sql = "select * from music order by musicName";
        Cursor cursor = sqLiteDatabase.rawQuery(sql,null);
        cursor.moveToFirst();
        do{
            long songId = cursor.getInt(cursor.getColumnIndex("songId"));
            long albumId = cursor.getInt(cursor.getColumnIndex("albumId"));
            int duration = cursor.getInt(cursor.getColumnIndex("duration"));
            String albumName = cursor.getString(cursor.getColumnIndex("albumName"));
            String albumData = cursor.getString(cursor.getColumnIndex("albumData"));
            String musicName = cursor.getString(cursor.getColumnIndex("musicName"));
            String artist = cursor.getString(cursor.getColumnIndex("artist"));
            long artistId = cursor.getInt(cursor.getColumnIndex("artistId"));
            String data = cursor.getString(cursor.getColumnIndex("data"));
            String folder = cursor.getString(cursor.getColumnIndex("folder"));
            String lrc = cursor.getString(cursor.getColumnIndex("lrc"));
            String sort = cursor.getString(cursor.getColumnIndex("sort"));
            int islocal = cursor.getInt(cursor.getColumnIndex("islocal"));
            int favorite = cursor.getInt(cursor.getColumnIndex("favorite"));
            Info music1= new Info();
            music1.setSongId(songId);
            music1.setAlbumId(albumId);
            music1.setDuration(duration);
            music1.setAlbumName(albumName);
            music1.setAlbumData(albumData);
            music1.setMusicName(musicName);
            music1.setArtist(artist);
            music1.setArtistId(artistId);
            music1.setData(data);
            music1.setFolder(folder);
            music1.setLrc(lrc);
            music1.setSort(sort);
            music1.setIslocal(islocal);
            music1.setFavorite(favorite);
            musicList.add(music1);

        }while(cursor.moveToNext());
        cursor.close();
        sqLiteDatabase.close();
        return musicList;
    }
    //返回字母排序歌曲名字
    public List<String> AlphabetmusicName(MusicSqLiteHelper musicSqLiteHelper){
        List<String> AlphabetmusicName = new ArrayList<>();
        SQLiteDatabase sqLiteDatabase = musicSqLiteHelper.getReadableDatabase();
        String sql = "select * from music order by musicName";
        Cursor cursor = sqLiteDatabase.rawQuery(sql,null);
        cursor.moveToLast();
        do{

            String musicName = cursor.getString(cursor.getColumnIndex("musicName"));
            AlphabetmusicName.add(musicName);

        }while(cursor.moveToPrevious());
        cursor.close();
        sqLiteDatabase.close();
        return AlphabetmusicName;
    }

    //时间顺序排序
    public List<Info> TimeLocalmusic(MusicSqLiteHelper musicSqLiteHelper){
        List<Info> musicList = new ArrayList<>();
        SQLiteDatabase sqLiteDatabase = musicSqLiteHelper.getReadableDatabase();
        String sql = "select * from music order by songId";
        Cursor cursor = sqLiteDatabase.rawQuery(sql,null);
        cursor.moveToLast();
        do{
            long songId = cursor.getInt(cursor.getColumnIndex("songId"));
            long albumId = cursor.getInt(cursor.getColumnIndex("albumId"));
            int duration = cursor.getInt(cursor.getColumnIndex("duration"));
            String albumName = cursor.getString(cursor.getColumnIndex("albumName"));
            String albumData = cursor.getString(cursor.getColumnIndex("albumData"));
            String musicName = cursor.getString(cursor.getColumnIndex("musicName"));
            String artist = cursor.getString(cursor.getColumnIndex("artist"));
            long artistId = cursor.getInt(cursor.getColumnIndex("artistId"));
            String data = cursor.getString(cursor.getColumnIndex("data"));
            String folder = cursor.getString(cursor.getColumnIndex("folder"));
            String lrc = cursor.getString(cursor.getColumnIndex("lrc"));
            String sort = cursor.getString(cursor.getColumnIndex("sort"));
            int islocal = cursor.getInt(cursor.getColumnIndex("islocal"));
            int favorite = cursor.getInt(cursor.getColumnIndex("favorite"));
            Info music1= new Info();
            music1.setSongId(songId);
            music1.setAlbumId(albumId);
            music1.setDuration(duration);
            music1.setAlbumName(albumName);
            music1.setAlbumData(albumData);
            music1.setMusicName(musicName);
            music1.setArtist(artist);
            music1.setArtistId(artistId);
            music1.setData(data);
            music1.setFolder(folder);
            music1.setLrc(lrc);
            music1.setSort(sort);
            music1.setIslocal(islocal);
            music1.setFavorite(favorite);
            musicList.add(music1);

        }while(cursor.moveToPrevious());
        cursor.close();
        sqLiteDatabase.close();
        return musicList;
    }
    //返回时间排序歌曲名字
    public List<String> TimeLocalmusicName(MusicSqLiteHelper musicSqLiteHelper){
        List<String> TimeLocalmusicName = new ArrayList<>();
        SQLiteDatabase sqLiteDatabase = musicSqLiteHelper.getReadableDatabase();
        String sql = "select * from music order by songId";
        Cursor cursor = sqLiteDatabase.rawQuery(sql,null);
        cursor.moveToLast();
        do{

            String musicName = cursor.getString(cursor.getColumnIndex("musicName"));
            TimeLocalmusicName.add(musicName);

        }while(cursor.moveToPrevious());
        cursor.close();
        sqLiteDatabase.close();
        return TimeLocalmusicName;
    }


    //作者顺序排序
    public List<Info> ArtistLocalmusic(MusicSqLiteHelper musicSqLiteHelper){
        List<Info> musicList = new ArrayList<>();
        SQLiteDatabase sqLiteDatabase = musicSqLiteHelper.getReadableDatabase();
        String sql = "select * from music order by artistId";
        Cursor cursor = sqLiteDatabase.rawQuery(sql,null);
        cursor.moveToFirst();
        do{
            long songId = cursor.getInt(cursor.getColumnIndex("songId"));
            long albumId = cursor.getInt(cursor.getColumnIndex("albumId"));
            int duration = cursor.getInt(cursor.getColumnIndex("duration"));
            String albumName = cursor.getString(cursor.getColumnIndex("albumName"));
            String albumData = cursor.getString(cursor.getColumnIndex("albumData"));
            String musicName = cursor.getString(cursor.getColumnIndex("musicName"));
            String artist = cursor.getString(cursor.getColumnIndex("artist"));
            long artistId = cursor.getInt(cursor.getColumnIndex("artistId"));
            String data = cursor.getString(cursor.getColumnIndex("data"));
            String folder = cursor.getString(cursor.getColumnIndex("folder"));
            String lrc = cursor.getString(cursor.getColumnIndex("lrc"));
            String sort = cursor.getString(cursor.getColumnIndex("sort"));
            int islocal = cursor.getInt(cursor.getColumnIndex("islocal"));
            int favorite = cursor.getInt(cursor.getColumnIndex("favorite"));
            Info music1= new Info();
            music1.setSongId(songId);
            music1.setAlbumId(albumId);
            music1.setDuration(duration);
            music1.setAlbumName(albumName);
            music1.setAlbumData(albumData);
            music1.setMusicName(musicName);
            music1.setArtist(artist);
            music1.setArtistId(artistId);
            music1.setData(data);
            music1.setFolder(folder);
            music1.setLrc(lrc);
            music1.setSort(sort);
            music1.setIslocal(islocal);
            music1.setFavorite(favorite);
            musicList.add(music1);

        }while(cursor.moveToNext());
        cursor.close();
        sqLiteDatabase.close();
        return musicList;
    }
    //返回作者排序歌曲名字
    public List<String> ArtistLocalmusicName(MusicSqLiteHelper musicSqLiteHelper){
        List<String> ArtistLocalmusicName = new ArrayList<>();
        SQLiteDatabase sqLiteDatabase = musicSqLiteHelper.getReadableDatabase();
        String sql = "select * from music order by artistId";
        Cursor cursor = sqLiteDatabase.rawQuery(sql,null);
        cursor.moveToLast();
        do{

            String musicName = cursor.getString(cursor.getColumnIndex("musicName"));
            ArtistLocalmusicName.add(musicName);

        }while(cursor.moveToPrevious());
        cursor.close();
        sqLiteDatabase.close();
        return ArtistLocalmusicName;
    }

    //字母顺序排序
    public List<Info> Alphabetmusic1(MusicSqLiteHelper musicSqLiteHelper){
        List<Info> musicList = new ArrayList<>();
        SQLiteDatabase sqLiteDatabase = musicSqLiteHelper.getReadableDatabase();
        String sql = "select * from favmusic order by musicName";
        Cursor cursor = sqLiteDatabase.rawQuery(sql,null);
        cursor.moveToFirst();
        do{
            long songId = cursor.getInt(cursor.getColumnIndex("songId"));
            long albumId = cursor.getInt(cursor.getColumnIndex("albumId"));
            int duration = cursor.getInt(cursor.getColumnIndex("duration"));
            String albumName = cursor.getString(cursor.getColumnIndex("albumName"));
            String albumData = cursor.getString(cursor.getColumnIndex("albumData"));
            String musicName = cursor.getString(cursor.getColumnIndex("musicName"));
            String artist = cursor.getString(cursor.getColumnIndex("artist"));
            long artistId = cursor.getInt(cursor.getColumnIndex("artistId"));
            String data = cursor.getString(cursor.getColumnIndex("data"));
            String folder = cursor.getString(cursor.getColumnIndex("folder"));
            String lrc = cursor.getString(cursor.getColumnIndex("lrc"));
            String sort = cursor.getString(cursor.getColumnIndex("sort"));
            int islocal = cursor.getInt(cursor.getColumnIndex("islocal"));
            int favorite = cursor.getInt(cursor.getColumnIndex("favorite"));
            Info music1= new Info();
            music1.setSongId(songId);
            music1.setAlbumId(albumId);
            music1.setDuration(duration);
            music1.setAlbumName(albumName);
            music1.setAlbumData(albumData);
            music1.setMusicName(musicName);
            music1.setArtist(artist);
            music1.setArtistId(artistId);
            music1.setData(data);
            music1.setFolder(folder);
            music1.setLrc(lrc);
            music1.setSort(sort);
            music1.setIslocal(islocal);
            music1.setFavorite(favorite);
            musicList.add(music1);

        }while(cursor.moveToNext());
        cursor.close();
        sqLiteDatabase.close();
        return musicList;
    }
    //返回字母排序歌曲名字
    public List<String> AlphabetmusicName1(MusicSqLiteHelper musicSqLiteHelper){
        List<String> AlphabetmusicName = new ArrayList<>();
        SQLiteDatabase sqLiteDatabase = musicSqLiteHelper.getReadableDatabase();
        String sql = "select * from favmusic order by musicName";
        Cursor cursor = sqLiteDatabase.rawQuery(sql,null);
        cursor.moveToLast();
        do{

            String musicName = cursor.getString(cursor.getColumnIndex("musicName"));
            AlphabetmusicName.add(musicName);

        }while(cursor.moveToPrevious());
        cursor.close();
        sqLiteDatabase.close();
        return AlphabetmusicName;
    }

    //时间顺序排序
    public List<Info> TimeLocalmusic1(MusicSqLiteHelper musicSqLiteHelper){
        List<Info> musicList = new ArrayList<>();
        SQLiteDatabase sqLiteDatabase = musicSqLiteHelper.getReadableDatabase();
        String sql = "select * from favmusic order by songId";
        Cursor cursor = sqLiteDatabase.rawQuery(sql,null);
        cursor.moveToLast();
        do{
            long songId = cursor.getInt(cursor.getColumnIndex("songId"));
            long albumId = cursor.getInt(cursor.getColumnIndex("albumId"));
            int duration = cursor.getInt(cursor.getColumnIndex("duration"));
            String albumName = cursor.getString(cursor.getColumnIndex("albumName"));
            String albumData = cursor.getString(cursor.getColumnIndex("albumData"));
            String musicName = cursor.getString(cursor.getColumnIndex("musicName"));
            String artist = cursor.getString(cursor.getColumnIndex("artist"));
            long artistId = cursor.getInt(cursor.getColumnIndex("artistId"));
            String data = cursor.getString(cursor.getColumnIndex("data"));
            String folder = cursor.getString(cursor.getColumnIndex("folder"));
            String lrc = cursor.getString(cursor.getColumnIndex("lrc"));
            String sort = cursor.getString(cursor.getColumnIndex("sort"));
            int islocal = cursor.getInt(cursor.getColumnIndex("islocal"));
            int favorite = cursor.getInt(cursor.getColumnIndex("favorite"));
            Info music1= new Info();
            music1.setSongId(songId);
            music1.setAlbumId(albumId);
            music1.setDuration(duration);
            music1.setAlbumName(albumName);
            music1.setAlbumData(albumData);
            music1.setMusicName(musicName);
            music1.setArtist(artist);
            music1.setArtistId(artistId);
            music1.setData(data);
            music1.setFolder(folder);
            music1.setLrc(lrc);
            music1.setSort(sort);
            music1.setIslocal(islocal);
            music1.setFavorite(favorite);
            musicList.add(music1);

        }while(cursor.moveToPrevious());
        cursor.close();
        sqLiteDatabase.close();
        return musicList;
    }
    //返回时间排序歌曲名字
    public List<String> TimeLocalmusicName1(MusicSqLiteHelper musicSqLiteHelper){
        List<String> TimeLocalmusicName = new ArrayList<>();
        SQLiteDatabase sqLiteDatabase = musicSqLiteHelper.getReadableDatabase();
        String sql = "select * from favmusic order by songId";
        Cursor cursor = sqLiteDatabase.rawQuery(sql,null);
        cursor.moveToLast();
        do{

            String musicName = cursor.getString(cursor.getColumnIndex("musicName"));
            TimeLocalmusicName.add(musicName);

        }while(cursor.moveToPrevious());
        cursor.close();
        sqLiteDatabase.close();
        return TimeLocalmusicName;
    }


    //作者顺序排序
    public List<Info> ArtistLocalmusic1(MusicSqLiteHelper musicSqLiteHelper){
        List<Info> musicList = new ArrayList<>();
        SQLiteDatabase sqLiteDatabase = musicSqLiteHelper.getReadableDatabase();
        String sql = "select * from favmusic order by artistId";
        Cursor cursor = sqLiteDatabase.rawQuery(sql,null);
        cursor.moveToFirst();
        do{
            long songId = cursor.getInt(cursor.getColumnIndex("songId"));
            long albumId = cursor.getInt(cursor.getColumnIndex("albumId"));
            int duration = cursor.getInt(cursor.getColumnIndex("duration"));
            String albumName = cursor.getString(cursor.getColumnIndex("albumName"));
            String albumData = cursor.getString(cursor.getColumnIndex("albumData"));
            String musicName = cursor.getString(cursor.getColumnIndex("musicName"));
            String artist = cursor.getString(cursor.getColumnIndex("artist"));
            long artistId = cursor.getInt(cursor.getColumnIndex("artistId"));
            String data = cursor.getString(cursor.getColumnIndex("data"));
            String folder = cursor.getString(cursor.getColumnIndex("folder"));
            String lrc = cursor.getString(cursor.getColumnIndex("lrc"));
            String sort = cursor.getString(cursor.getColumnIndex("sort"));
            int islocal = cursor.getInt(cursor.getColumnIndex("islocal"));
            int favorite = cursor.getInt(cursor.getColumnIndex("favorite"));
            Info music1= new Info();
            music1.setSongId(songId);
            music1.setAlbumId(albumId);
            music1.setDuration(duration);
            music1.setAlbumName(albumName);
            music1.setAlbumData(albumData);
            music1.setMusicName(musicName);
            music1.setArtist(artist);
            music1.setArtistId(artistId);
            music1.setData(data);
            music1.setFolder(folder);
            music1.setLrc(lrc);
            music1.setSort(sort);
            music1.setIslocal(islocal);
            music1.setFavorite(favorite);
            musicList.add(music1);

        }while(cursor.moveToNext());
        cursor.close();
        sqLiteDatabase.close();
        return musicList;
    }
    //返回作者排序歌曲名字
    public List<String> ArtistLocalmusicName1(MusicSqLiteHelper musicSqLiteHelper){
        List<String> ArtistLocalmusicName = new ArrayList<>();
        SQLiteDatabase sqLiteDatabase = musicSqLiteHelper.getReadableDatabase();
        String sql = "select * from favmusic order by artistId";
        Cursor cursor = sqLiteDatabase.rawQuery(sql,null);
        cursor.moveToLast();
        do{

            String musicName = cursor.getString(cursor.getColumnIndex("musicName"));
            ArtistLocalmusicName.add(musicName);

        }while(cursor.moveToPrevious());
        cursor.close();
        sqLiteDatabase.close();
        return ArtistLocalmusicName;
    }

    //字母顺序排序
    public List<Info> Alphabetmusic2(MusicSqLiteHelper musicSqLiteHelper){
        List<Info> musicList = new ArrayList<>();
        SQLiteDatabase sqLiteDatabase = musicSqLiteHelper.getReadableDatabase();
        String sql = "select * from remusic order by musicName";
        Cursor cursor = sqLiteDatabase.rawQuery(sql,null);
        cursor.moveToFirst();
        do{
            long songId = cursor.getInt(cursor.getColumnIndex("songId"));
            long albumId = cursor.getInt(cursor.getColumnIndex("albumId"));
            int duration = cursor.getInt(cursor.getColumnIndex("duration"));
            String albumName = cursor.getString(cursor.getColumnIndex("albumName"));
            String albumData = cursor.getString(cursor.getColumnIndex("albumData"));
            String musicName = cursor.getString(cursor.getColumnIndex("musicName"));
            String artist = cursor.getString(cursor.getColumnIndex("artist"));
            long artistId = cursor.getInt(cursor.getColumnIndex("artistId"));
            String data = cursor.getString(cursor.getColumnIndex("data"));
            String folder = cursor.getString(cursor.getColumnIndex("folder"));
            String lrc = cursor.getString(cursor.getColumnIndex("lrc"));
            String sort = cursor.getString(cursor.getColumnIndex("sort"));
            int islocal = cursor.getInt(cursor.getColumnIndex("islocal"));
            int favorite = cursor.getInt(cursor.getColumnIndex("favorite"));
            Info music1= new Info();
            music1.setSongId(songId);
            music1.setAlbumId(albumId);
            music1.setDuration(duration);
            music1.setAlbumName(albumName);
            music1.setAlbumData(albumData);
            music1.setMusicName(musicName);
            music1.setArtist(artist);
            music1.setArtistId(artistId);
            music1.setData(data);
            music1.setFolder(folder);
            music1.setLrc(lrc);
            music1.setSort(sort);
            music1.setIslocal(islocal);
            music1.setFavorite(favorite);
            musicList.add(music1);

        }while(cursor.moveToNext());
        cursor.close();
        sqLiteDatabase.close();
        return musicList;
    }
    //返回字母排序歌曲名字
    public List<String> AlphabetmusicName2(MusicSqLiteHelper musicSqLiteHelper){
        List<String> AlphabetmusicName = new ArrayList<>();
        SQLiteDatabase sqLiteDatabase = musicSqLiteHelper.getReadableDatabase();
        String sql = "select * from remusic order by musicName";
        Cursor cursor = sqLiteDatabase.rawQuery(sql,null);
        cursor.moveToLast();
        do{

            String musicName = cursor.getString(cursor.getColumnIndex("musicName"));
            AlphabetmusicName.add(musicName);

        }while(cursor.moveToPrevious());
        cursor.close();
        sqLiteDatabase.close();
        return AlphabetmusicName;
    }

    //时间顺序排序
    public List<Info> TimeLocalmusic2(MusicSqLiteHelper musicSqLiteHelper){
        List<Info> musicList = new ArrayList<>();
        SQLiteDatabase sqLiteDatabase = musicSqLiteHelper.getReadableDatabase();
        String sql = "select * from remusic order by songId";
        Cursor cursor = sqLiteDatabase.rawQuery(sql,null);
        cursor.moveToLast();
        do{
            long songId = cursor.getInt(cursor.getColumnIndex("songId"));
            long albumId = cursor.getInt(cursor.getColumnIndex("albumId"));
            int duration = cursor.getInt(cursor.getColumnIndex("duration"));
            String albumName = cursor.getString(cursor.getColumnIndex("albumName"));
            String albumData = cursor.getString(cursor.getColumnIndex("albumData"));
            String musicName = cursor.getString(cursor.getColumnIndex("musicName"));
            String artist = cursor.getString(cursor.getColumnIndex("artist"));
            long artistId = cursor.getInt(cursor.getColumnIndex("artistId"));
            String data = cursor.getString(cursor.getColumnIndex("data"));
            String folder = cursor.getString(cursor.getColumnIndex("folder"));
            String lrc = cursor.getString(cursor.getColumnIndex("lrc"));
            String sort = cursor.getString(cursor.getColumnIndex("sort"));
            int islocal = cursor.getInt(cursor.getColumnIndex("islocal"));
            int favorite = cursor.getInt(cursor.getColumnIndex("favorite"));
            Info music1= new Info();
            music1.setSongId(songId);
            music1.setAlbumId(albumId);
            music1.setDuration(duration);
            music1.setAlbumName(albumName);
            music1.setAlbumData(albumData);
            music1.setMusicName(musicName);
            music1.setArtist(artist);
            music1.setArtistId(artistId);
            music1.setData(data);
            music1.setFolder(folder);
            music1.setLrc(lrc);
            music1.setSort(sort);
            music1.setIslocal(islocal);
            music1.setFavorite(favorite);
            musicList.add(music1);

        }while(cursor.moveToPrevious());
        cursor.close();
        sqLiteDatabase.close();
        return musicList;
    }
    //返回时间排序歌曲名字
    public List<String> TimeLocalmusicName2(MusicSqLiteHelper musicSqLiteHelper){
        List<String> TimeLocalmusicName = new ArrayList<>();
        SQLiteDatabase sqLiteDatabase = musicSqLiteHelper.getReadableDatabase();
        String sql = "select * from remusic order by songId";
        Cursor cursor = sqLiteDatabase.rawQuery(sql,null);
        cursor.moveToLast();
        do{

            String musicName = cursor.getString(cursor.getColumnIndex("musicName"));
            TimeLocalmusicName.add(musicName);

        }while(cursor.moveToPrevious());
        cursor.close();
        sqLiteDatabase.close();
        return TimeLocalmusicName;
    }


    //作者顺序排序
    public List<Info> ArtistLocalmusic2(MusicSqLiteHelper musicSqLiteHelper){
        List<Info> musicList = new ArrayList<>();
        SQLiteDatabase sqLiteDatabase = musicSqLiteHelper.getReadableDatabase();
        String sql = "select * from remusic order by artistId";
        Cursor cursor = sqLiteDatabase.rawQuery(sql,null);
        cursor.moveToFirst();
        do{
            long songId = cursor.getInt(cursor.getColumnIndex("songId"));
            long albumId = cursor.getInt(cursor.getColumnIndex("albumId"));
            int duration = cursor.getInt(cursor.getColumnIndex("duration"));
            String albumName = cursor.getString(cursor.getColumnIndex("albumName"));
            String albumData = cursor.getString(cursor.getColumnIndex("albumData"));
            String musicName = cursor.getString(cursor.getColumnIndex("musicName"));
            String artist = cursor.getString(cursor.getColumnIndex("artist"));
            long artistId = cursor.getInt(cursor.getColumnIndex("artistId"));
            String data = cursor.getString(cursor.getColumnIndex("data"));
            String folder = cursor.getString(cursor.getColumnIndex("folder"));
            String lrc = cursor.getString(cursor.getColumnIndex("lrc"));
            String sort = cursor.getString(cursor.getColumnIndex("sort"));
            int islocal = cursor.getInt(cursor.getColumnIndex("islocal"));
            int favorite = cursor.getInt(cursor.getColumnIndex("favorite"));
            Info music1= new Info();
            music1.setSongId(songId);
            music1.setAlbumId(albumId);
            music1.setDuration(duration);
            music1.setAlbumName(albumName);
            music1.setAlbumData(albumData);
            music1.setMusicName(musicName);
            music1.setArtist(artist);
            music1.setArtistId(artistId);
            music1.setData(data);
            music1.setFolder(folder);
            music1.setLrc(lrc);
            music1.setSort(sort);
            music1.setIslocal(islocal);
            music1.setFavorite(favorite);
            musicList.add(music1);

        }while(cursor.moveToNext());
        cursor.close();
        sqLiteDatabase.close();
        return musicList;
    }
    //返回作者排序歌曲名字
    public List<String> ArtistLocalmusicName2(MusicSqLiteHelper musicSqLiteHelper){
        List<String> ArtistLocalmusicName = new ArrayList<>();
        SQLiteDatabase sqLiteDatabase = musicSqLiteHelper.getReadableDatabase();
        String sql = "select * from remusic order by artistId";
        Cursor cursor = sqLiteDatabase.rawQuery(sql,null);
        cursor.moveToLast();
        do{

            String musicName = cursor.getString(cursor.getColumnIndex("musicName"));
            ArtistLocalmusicName.add(musicName);

        }while(cursor.moveToPrevious());
        cursor.close();
        sqLiteDatabase.close();
        return ArtistLocalmusicName;
    }


}